<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.sql.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> 
<%@ include file="/include/head.jsp"%>
<%
request.setCharacterEncoding("UTF-8");
String htmlData = request.getParameter("content") != null ? request.getParameter("content") : "";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="<%=request.getContextPath()%>/resources/kindeditor/kindeditor.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/resources/kindeditor/plugins/code/prettify.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/resources/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/resources/kindeditor/plugins/code/prettify.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/resources/servicePro/jquery.uploadify.min.js"></script>
<link rel="stylesheet" href="<%=request.getContextPath()%>/resources/kindeditor/themes/default/default.css" />
<link rel="stylesheet" href="<%=request.getContextPath()%>/resources/kindeditor/plugins/code/prettify.css" />
<link rel="stylesheet" href="<%=request.getContextPath()%>/resources/servicePro/uploadify.css">
<script type="text/javascript">
      var editor;
      KindEditor.ready(function(K) {
			editor = K.create('textarea[name="content"]', {
				uploadJson : '<%=request.getContextPath()%>/back/page/imagePageUpload.do',
				fileManagerJson : '<%=request.getContextPath()%>/back/page/filePageUpload.do',
				allowFileManager : true,
				 afterBlur: function() {
				this.sync();
				}
			});
			prettyPrint();
		});
		//修改资讯
		function updateNews(){
		  var id=$('#id').val();
		  var title=$('#title').val();
          var content= $('#content').val();
          var author= $('#author').val();
          var intro=$('#intro').val();
			var col1=$('#iphoto_col1').val();
			var col2=$('#iphoto_col2').val();
			var col3=$('#iphoto_col3').val();
           if(title.length==0  || content.length==0||author.length==0||id.length==0||intro.length==0){
	      alert("输入信息不能为空!");
	        return false;
	    } 
           $.ajax({
					type : "POST",
					url : "<%=request.getContextPath()%>/back/news/updateNews.do",
					dataType : "json",
					data:{
					"id":id,
					"title":title,
					"author":author,
					"content":content,
					"intro":intro,
						"col1":col1,
						"col2":col2,
						"col3":col3
					},
					async : false,
					success : function(data) {
						if(data.code=="0000"){
			       		 alert("操作成功!");
			       		 layer.open({
					              type: 1,
					              title: false,
					              closeBtn: 2,
					              shadeClose: true,
					              skin: 'layui-layer-nobg',
					              content: "<input style=\"width:100px;height:50px;\" class=\"common_btn jbxx_btn\"  onclick =\"go();\" type=\"button\" value=\"继续修改\">"+
					                       "<input style=\"width:100px;height:50px;\" class=\"common_btn jbxx_btn\"  onclick =\"gotolist();\" type=\"button\" value=\"返回列表\">"
                                    });
			       }else{
			           alert(data.code+data.codeMsg);
			       }
					}
				});//AJAx end 
		} 
		/**继续添加*/ 
		function go(){
		 location.reload();
		}
		/***返回列表**/
		function gotolist(){
		   window.location.href='<%=request.getContextPath()%>/back/news/getNewsBeans.do';
		}
</script>
  </head>
  
  <body>
   <!-- 遮罩用的div -->
		<div id="divLayer"></div>
		<div class="userr"  >
			<div class="user_borders box_pet"  >
				<div class="r_petmid">
				<form id="submitNews" name="example" method="post" action="" >
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tbody>
								<tr>
									<td width="100" height="70" class="r_name">
									<span class="font_red ml10">*</span>标题：</td>
									<td class="r_namer">
									<input type="hidden" name="id" id="id"  value="${newsBean.id }"/>
									<input id="title"  name="title" type="text" class="r_form1" value="${ newsBean.title}"  />
									<span id="titleTs" class="fontpink" ></span>
									</td>
								</tr>
								<tr>
									<td width="100" height="70" class="r_name">
									<span class="font_red ml10">*</span>作者：</td>
									<td class="r_namer">
									<input id="author"  name="author" type="text" class="r_form1" value="${newsBean.author }"/>
									<span id="titleTs" class="fontpink" ></span>
									</td>
								</tr>
								 <tr>
									<td height="140" class="r_name t_indent10">简介：</td>
									<td class="r_namer"><label> <textarea
												name="intro"
												onkeyup="this.value=this.value.substring(0,1000)" id="intro"
												cols="100" rows="4" style="resize: none;">${newsBean.intro }</textarea>
									</label></td>
								</tr>
								  <tr>
								  <td width="100" height="70" class="r_name">
									<span class="font_red ml10">*</span>内容：</td>
								  <td class="r_namer">
								  <textarea id="content"   name="content" style="width:800px;height:400px;visibility:hidden;" >${newsBean.content }</textarea>								
								  </td>
								  </tr>
								<tr>
									<td width="100" height="70" class="r_name">前台首页大图</td>
									<td>
										<div>
											<c:if test="${newsBean.col1 != null}">
												<img width="50" height="50" src="<%=imgPath %>${newsBean.col1 }" alt=""/>
											</c:if>

											<input type="hidden" id="iphoto_col1"   name="col1" value="<c:out value="${newsBean.col1}" />"/>
											<input type="file" name="fileName_col1" class="ml10" style="height:36px;" id="file_upload_col1" />
											<input id="uploadButton_col1" type="button"
												   onclick="$('#file_upload_col1').uploadify('upload');" value="开始上传"
												   class="ext_btn ext_btn_success" style="display:none;">
											<p class="fontpink" id="onlyOneImg_col1" style="display:none;">只能上传一张图片</p>
										</div>
									</td>
									</td>
								</tr>
								<tr>
									<td width="100" height="70" class="r_name">安卓二维码</td>
									<td>
										<div>
											<c:if test="${newsBean.col2 != null}">
												<img width="50" height="50" src="<%=imgPath %>${newsBean.col2 }" alt=""/>
											</c:if>

											<input type="hidden" id="iphoto_col2"   name="col2" value="<c:out value="${newsBean.col2}" />"/>
											<input type="file" name="fileName_col2" class="ml10" style="height:36px;" id="file_upload_col2" />
											<input id="uploadButton_col2" type="button"
												   onclick="$('#file_upload_col2').uploadify('upload');" value="开始上传"
												   class="ext_btn ext_btn_success" style="display:none;">
											<p class="fontpink" id="onlyOneImg_col2" style="display:none;">只能上传一张图片</p>
										</div>
									</td>
									</td>
								</tr>
								<tr>
									<td width="100" height="70" class="r_name">微信公众号二维码</td>
									<td>
										<div>
											<input type="hidden" id="iphoto_col3" name="col3" value="<c:out value="${newsBean.col3}" />" />
											<c:if test="${newsBean.col3 != null}">
												<img width="50" height="50" src="<%=imgPath %>${newsBean.col3 }" alt=""/>
											</c:if>

											<input type="file" name="fileName_col3" class="ml10" style="height:36px;" id="file_upload_col3" />
											<input id="uploadButton_col3" type="button"
												   onclick="$('#file_upload_col3').uploadify('upload');" value="开始上传"
												   class="ext_btn ext_btn_success" style="display:none;">
											<p class="fontpink" id="onlyOneImg_col3" style="display:none;">只能上传一张图片</p>
										</div>
									</td>
									</td>
								</tr>
								<tr>
									<td class="r_namer">
									<input type="button" value="提交" class="new_btn new_btn_submit new_btn_exbig" onclick="updateNews()" /> 
									</td>
								</tr>
							</tbody>
						</table>
					</form>
				</div>
			</div>
		</div>
  <script type="application/javascript">
	  $(function () {
		  image('_col1');
		  image('_col2');
		  image('_col3');
	  });




	  function image(col) {
		  $("#file_upload"+col).uploadify({
			  'buttonText' : '请选择活动图片',
			  'height' : 30,
			  'swf' : '<%=request.getContextPath()%>/resources/servicePro/uploadify.swf',
			  'uploader' : '<%=request.getContextPath()%>/back/actBack/uploadlogo.do',
			  'width' : 120,
			  'multi'           : false,
			  "auto"            : false,
			  "dnd"             : true,
			  "fileTypeExts"    : "*.png;*.jpg;*.bmp;*.gif",
			  "fileSizeLimit"   : "2MB",
			  'fileObjName'   : 'file',
			  'onUploadSuccess' : function(file, data, response) {
				  data = eval("(" + data + ")");
				  alert( file.name + ' 上传成功！ ');
				  $("#iphoto"+col).val(data.picurl);
				  $("#uploadButton"+col).hide();

			  },
			  'onFallback' : function() {
				  alert('Flash was not detected.');
			  },
			  "onSelect" : function(file) {
				  if ($("#file_upload"+col+"-queue").children().length == 1) {
					  $("#uploadButton"+col).show();
					  $("#onlyOneImg"+col).hide();
				  } else {

					  $("#uploadButton"+col).hide();
					  $("#onlyOneImg"+col).show();
				  }
			  },
			  "onCancel" : function() {
				  if ($("#file_upload-queue"+col).children().length == 2) {
					  $("#uploadButton"+col).show();
					  $("#onlyOneImg"+col).hide();
				  } else if ($("#file_upload-queue"+col).children().length == 1) {
					  $("#uploadButton"+col).hide();
				  } else {
					  $("#uploadButton"+col).hide();
					  $("#onlyOneImg"+col).show();
				  }
			  },
		  });
	  }
  </script>
  </body>
  
</html>
<%!
private String htmlspecialchars(String str) {
	str = str.replaceAll("&", "&amp;");
	str = str.replaceAll("<", "&lt;");
	str = str.replaceAll(">", "&gt;");
	str = str.replaceAll("\"", "&quot;");
	return str;
}
%>
